package com.jzo2o.customer.controller.consumer;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.dto.PageQueryDTO;
import com.jzo2o.customer.model.domain.AddressBookSelectDto;
import com.jzo2o.customer.model.dto.request.AddressBookUpsertReqDTO;
import com.jzo2o.customer.service.IAddressBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 86135
 */
@Slf4j
@RestController("AddressBook")
@RequestMapping("/consumer/address-book")
@Api(tags = "用户端 - 地址端口")
public class AddressBook {
    @Resource
    IAddressBookService addressBookService;


    @PostMapping
    @ApiOperation("地址新增")
    public void addAddressBookInsert (@RequestBody AddressBookUpsertReqDTO dto) {
        addressBookService.Insert(dto);
    }

    @GetMapping("/page")
    @ApiOperation("地址分页查询")
    public PageResult<AddressBookSelectDto> addAddressBookSelect(PageQueryDTO dto){
       return addressBookService.select(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("查询编辑地址id")
    public AddressBookSelectDto  addAddressBookSelectId(@PathVariable Long id){
      return  addressBookService.selectId(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("编辑地址")
    public void   addAddressBookPutId(@RequestBody AddressBookUpsertReqDTO dto,@PathVariable Long id){
        addressBookService.putId(dto,id);
    }


    @DeleteMapping("/batch")
    @ApiOperation("删除地址")
    public void addAddressBookDelete(@RequestBody List<String> ids){
      addressBookService.deleteIds(ids);
    }

    @PutMapping("/default")
    @ApiOperation("设置/取消默认地址")
    public void addAddressBookDefault(int flag,long id){
        addressBookService.defaultOne(flag,id);
    }

    @GetMapping("defaultAddress")
    @ApiOperation("获取默认地址接口")
    public AddressBookSelectDto addAddressBookDefault(){
        return addressBookService.selectDefault();
    }
}
